<?php
class Account extends MY_Controller{
	
	function __construct()
	{
		parent::__construct();
		if(!$this->aauth->is_loggedin()){
			redirect('login');
		}
		$this->aauth->update_activity();
	}
	
	function index()
	{
		$user = $this->aauth->get_user();
		if($_POST){			
			$code = $_POST['code'] ;
			if($code == 'name'){
				$this->form_validation->set_rules('name', '用户名称', 'required');
				$this->form_validation->set_error_delimiters('<div class="text-red">', '</div>');
				if (!$this->form_validation->run() == FALSE){
				$update = $this->aauth->update_user($user->id, FALSE, FALSE, $_POST['name']);
				$user = $this->aauth->get_user();
				$data['msg'] = '用户名称修改成功.';
				}
			}else{
				$this->form_validation->set_rules('password', '密码', 'required|min_length[6]|max_length[12]|matches[passconf]');
				$this->form_validation->set_rules('passconf', '密码确认', 'required');
				$this->form_validation->set_error_delimiters('<div class="text-red">', '</div>');
				if (!$this->form_validation->run() == FALSE){
				$update = $this->aauth->update_user($user->id, FALSE, $_POST['password'], FALSE);
				$data['msg'] = '密码修改成功.';
				}
			}
		}
		$data['user'] = $user;
		$data['title'] = $this->title('我的账户');
		$this->load->view($this->theme.'/header',$data);
		$this->load->view($this->theme.'/account/index');
		$this->load->view($this->theme.'/footer');
	}
	
	
}